package cn.yours.web.handler;


import cn.yours.web.exception.BaseException;
import cn.yours.web.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * 2024/6/4 22:56
 * wuhon
 * cn.kong.web.handler
 * spring-elfinder
 */
@ControllerAdvice
@Slf4j
public class GloabalExceptionHandler {
    /**
     * 不能删除admin管理员用户
     *
     * @param
     * @return
     */
    @ExceptionHandler(BaseException.class)
    @ResponseBody
    public Result<Object> handleBaseException(BaseException baseException){
        log.info("发生业务异常");
        return Result.error(1010, baseException.getMessage());
    }
    /**
     * 不能删除admin管理员用户
     *
     * @param sqlException
     * @return
     */
    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result<Object> handleSQLException(SQLException sqlException){
        log.info("不能删除admin管理员用户");
        return Result.error(9999, "不能删除admin管理员用户");
    }
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result<Object> handleRuntimeException(RuntimeException ex) {
        log.error("异常信息：{}", ex.getMessage());
        return Result.error(500, "系统出错了，请联系管理员");
    }
}
